import type { PropType } from 'vue'
import type { ExtrackExpose, ExtractProps } from '@/utils/type'
import { ProgressNS } from '@/components'
import type Com from './index.vue'
import { useNamespace } from '@/utils'

export namespace variables {
  /** 动画过渡时间，毫秒 */
  export const transitionTime = .5 * 1000
  /** progress 多读时间，毫秒 */
  export const progressTransitionTime = .3 * 1000
  export const ns = useNamespace('LoadPage')
}
export namespace LoadPageNS {
  export const name = variables.ns.name
  export const props = {
    /**
     * 是否组件挂载后自动加载
     * @默认 true
     */
    auto: {
      type: Boolean,
      default: true
    },
    /**
     * 加载函数
     */
    load: {
      type: Function as PropType<() => any>,
      required: true as const
    },
    /**
     * 是否显示版权声明
     */
    showCopyright: Boolean,
    /**
     * 进度条
     */
    progress: Object as PropType<Omit<ProgressNS.Props,
      keyof Pick<ProgressNS.Props, 'current' | 'total'>>>,
  }
  export const emits = {
    /**
     * 开始加载
     */
    start: () => true,
    /**
     * 加载成功
     */
    success: () => true,
    /**
     * 加载失败
     */
    fail: (_err: any) => true,
    /**
     * 加载完成
     */
    complete: () => true
  }
  export type Props = ExtractProps.Types<typeof props> & PartialEmits<typeof emits>
  export const Component = <{
    new(): {
      $props: Props
    }
  }>{}
  export type Instance = ExtrackExpose.Types<typeof Com>
}